package org.come.baitan;

import javax.swing.*;
import java.awt.*;

/**
 * @author 式
 * @version 1.0
 * @project test1
 * @description 收购列表
 * @date 2024/1/29 22:48:13
 */
public class myRenderer extends JPanel implements ListCellRenderer{
private int index;
public static String vs;
private static DefaultListModel<String> listModel;
private BaiTanJpanel baiTanJpanel;
public myRenderer(BaiTanJpanel baiTanJpanel) {
	this.index = 67;
	this.baiTanJpanel=baiTanJpanel;
}

public myRenderer(final int index) {
	this.index = 67;
	this.index = index;
}
@Override
public Dimension getPreferredSize() {
	return new Dimension(this.getWidth() / 2, 22);
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
	final myRenderer mr = new myRenderer(index);
	mr.removeAll();
	if (baiTanJpanel.index == index || isSelected) {
		mr.setBackground(Color.GRAY);
	}
	else {
		mr.setOpaque(false);
	}
	mr.setLayout(new FlowLayout(0));
	final Box box = Box.createHorizontalBox();
	box.add(new JLabel(value.toString()) {
		{
			this.setFont(new Font("宋体", 0, 14));
			this.setForeground(Color.white);
			if (isSelected) {
				mr.setBackground(Color.gray);
				this.setForeground(Color.red);
			}
		}
	});
	mr.add((Component)box);
	return (Component)mr;
}

}
